Skip to content

Cache asSeenFrom results per context - #26778

Draft
tanishiking wants to merge 2 commits into
scala:mainfrom
dotty-staging:asseenfrom-ctx-cache
Draft

Cache asSeenFrom results per context#26778
tanishiking wants to merge 2 commits into
scala:mainfrom
dotty-staging:asseenfrom-ctx-cache

Conversation

@tanishiking

@tanishiking tanishiking commented Aug 11, 2026

Copy link
Copy Markdown
Member

Fixes #26777

Cache TypeOps$.asSeenFrom. Described details on #26777

Have you relied on LLM-based tools in this contribution?

Yes, mostly for discussing how to cache TypeOps$.asSeenFrom safely, and ended up storing cache in Context and using GenericHashMap for it's keys (but I'm doubting about this 🤔 )

How was the solution tested?

Covered by existing tests (this is a refactoring)

else
val cache = ctx.asSeenFromCache
val key = (tp, pre, cls)
val cached = cache.lookup(key)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GenericHashMap has a getOrElseUpdate to avoid doing the hashing/lookup twice, I think it can be used here? Although I guess the stats need to become "total requests" + "miss" instead.

@dottybot

Copy link
Copy Markdown
Member

Benchmarks started. Workflow run.

@dottybot

Copy link
Copy Markdown
Member

Benchmarks completed. Overview.

@SolalPirelli

SolalPirelli commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Nice win for scalaz as expected, but fansi and tastyQuery seem to regress badly

@tanishiking

Copy link
Copy Markdown
Member Author

Yeah, we can't merge this as-is 😞 I'll take a look how can we reduce the regress / improve cache hit rate at some point.

silverlining: what we changed in this PR is adding a small number of allocation, storing to cache, and isProvisinal checks. So maybe even a small micro optimization around asSeenFrom could lead to a nice optimization result on those benchmarks 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Report] Optimization attempt: cache TypeOps$.asSeenFrom

3 participants